﻿#ifndef INVENTORYVIEW_H
#define INVENTORYVIEW_H
#include"XQOperateView.h"
#include"InventoryModel.h"
class InventoryView :public XQOperateView
{
	Q_OBJECT
public:
	InventoryView(QWidget* parent = nullptr);
	~InventoryView();
	enum class Type;
public:
	void setReadOnly(bool readOnly)override;
	void setReadOnly(int type, bool readOnly)override;
	template<typename T = Type>
	void setReadOnly(T type, bool readOnly);
public:
	InventoryModel inventoryModel()const;
	quint64 inventory_id()const;
	QString name()const;
	QString type()const;
	//当前库存
	quint64 currentInventory()const;
	//安全库存
	quint64 safetyInventory()const;
	//补货量
	quint64 restockingQuantity()const;
	QDateTime mtime()const;
	QDateTime ctime()const;
public:
	void setInventoryModel(const InventoryModel& model);
	void setInventory_id(quint64 id);
	void setName(const QString& name);
	void setType(const QString& type);
	void setCurrentInventory(quint64 currentInventory);
	void setSafetyInventory(quint64 safetyInventory);
	void setRestockingQuantity(quint64 restockingQuantity);
	void setMTime(const QDateTime& time);
	void setCTime(const QDateTime& time);

	void setTypeCompleter(const QStringList& list);
	void setTypeItems(const QStringList& list);
	void setAutoRestockingQuantity(bool Auto);
public:
	//初始化
	void init()override;
	void okButtonSlots()override;
protected://初始化和ui界面
	//初始化UI
	virtual void init_ui();
	QWidget* init_id();
	QWidget* init_name();
	QWidget* init_type();
	QWidget* init_currentInventory();
	QWidget* init_safetyInventory();
	QWidget* init_restockingQuantity();
	//修改时间初始化
	virtual QWidget* init_mtimeEdit();
	//创建时间初始化
	virtual QWidget* init_ctimeEdit();
protected:
	QLineEdit* m_idEdit = nullptr;
	QLineEdit* m_nameEdit = nullptr;
	QComboBox* m_typeEdit = nullptr;
	QLineEdit* m_currentInventoryEdit = nullptr;
	QLineEdit* m_safetyInventoryEdit = nullptr;
	QLineEdit* m_restockingQuantityEdit = nullptr;
	QDateTimeEdit* m_mtimeEdit = nullptr;//修改时间编辑框
	QDateTimeEdit* m_ctimeEdit = nullptr;//创建时间编辑框
	bool m_autoRestockingQuantity = false;
};

enum class InventoryView::Type
{
	OkButtonType,
	CloseButtonType,
	IdType,
	NameType,
	TypeType,
	CurrentInventoryType,
	SafetyInventoryType,
	RestockingQuantityType,
	MtimeType,
	CtimeType,
};
template<typename T>
inline void InventoryView::setReadOnly(T type, bool readOnly)
{
	setReadOnly((int)type,readOnly);
}
#endif
